package com.jxaummd.mushroom.core.base.fragment;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.ColorInt;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


import com.jxaummd.mushroom.core.wiget.convention.PlaceHolderView;

import butterknife.ButterKnife;
import butterknife.Unbinder;
import me.yokeyword.fragmentation_swipeback.SwipeBackFragment;

public abstract class BaseFragment extends SwipeBackFragment {

    //ButterKnife 解绑
    @SuppressWarnings("SpellCheckingInspection")
    private Unbinder mUnbinder = null;

    protected PlaceHolderView mPlaceHolderView;

    private FragmentActivity mFragmentActivity = null;

    /**
     * 设置layout
     *
     * @return
     */
    public abstract Object setLayout();

    /**
     * 视图逻辑绑定
     *
     * @param savedInstanceState
     * @param rootView
     */
    public abstract void onBindView(@Nullable Bundle savedInstanceState, View rootView);

    /**
     * 透明状态状态栏
     */
    public void setTranlucentStatusBar(boolean istrans, boolean ishidebackground) {
        if (istrans) {
            //translucent status bar
//            StatusBarCompat.translucentStatusBar(getProxyActivity(), ishidebackground);
        }
    }

    /**
     * 设置状态栏颜色
     *
     * @param color
     */
    public void setStatusBarColor(@ColorInt int color) {
//        StatusBarCompat.setStatusBarColor(getProxyActivity(), color);
    }

    /**
     * 设置全屏幕显示
     *
     * @param flag
     */
    public void setFullScreen(boolean flag) {
        if (flag) {
//            StatusBarCompat.setFullScreen(getProxyAppCompatActivity(), StatusBarCompat.STATUEBAR_FULLSCREEN);
        } else {
//            StatusBarCompat.setFullScreen(getProxyAppCompatActivity(), StatusBarCompat.STATUEBAR_NORMAL);
        }

    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        Bundle args = new Bundle();
//        setArguments(args);
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        this.mFragmentActivity = (FragmentActivity) activity;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        final View rootView;
        if (setLayout() instanceof Integer) {
            rootView = inflater.inflate((Integer) setLayout(), container, false);
        } else if (setLayout() instanceof View) {
            rootView = (View) setLayout();
        } else {
            throw new ClassCastException("type of setLayout() must be int or View!"+this.getClass().getName());
        }
        mUnbinder = ButterKnife.bind(this, rootView);

        onBindView(savedInstanceState, rootView);
//        if(isSwipBack)
//            return attachToSwipeBack(rootView);
        return rootView;
    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        //解除绑定
        if (mUnbinder != null) {
            mUnbinder.unbind();
        }
        hideSoftInput();
    }

    public final AppCompatActivity getProxyActivity() {
        return (AppCompatActivity) _mActivity;
    }

    public final void finshActivity() {
        _mActivity.finish();
    }

    /**
     * 设置占位布局
     *
     * @param placeHolderView 继承了占位布局规范的View
     */
    public void setPlaceHolderView(PlaceHolderView placeHolderView) {
        this.mPlaceHolderView = placeHolderView;
    }

}
